package com.googlecode.fs_thumbs;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;

public class Config {

	private ResourceBundle bundle;
	private final Properties props = new Properties();;

	public Config(final String name) throws FileNotFoundException, IOException {
		bundle = ResourceBundle.getBundle("config");
		if (name != null) {
			props.load(new FileInputStream(new File(name)));
		}
	}

	public String get(final String key) {
		return props.getProperty(key, bundle.getString(key));
	}

	public String get(final String... keys) {
		for (String key : keys) {
			final String property = props.getProperty(key);
			if (property != null) {
				return property;
			}
		}
		for (String key : keys) {
			try {
				return bundle.getString(key);
			} catch (MissingResourceException exception) {
				// just try the next
			}
		}
		return "";
	}
}
